<template>
  <div :class="className" :style="{height:height,width:width}" />
</template>

<script>
import * as echarts from 'echarts'
require('echarts/theme/royal') // echarts theme
import { debounce } from '@/utils'

const animationDuration = 6000

export default {
  props: {
    className: {
      type: String,
      default: 'chart'
    },
    width: {
      type: String,
      default: '100%'
    },
    height: {
      type: String,
      default: '300px'
    },
    optionTitleText: {
      type: String,
      default: ''
    }
  },
  data() {
    return {
      chart: null,
      opinion:{
        // title: {
        //   text: '情感分析'
        // },
        tooltip: {
          trigger: 'axis'
        },
        legend: {
          data: ['新闻', '微信', '博客','微博','论坛','贴吧','APP']
        },
        grid: {
          left: '3%',
          right: '4%',
          bottom: '3%',
          containLabel: true
        },
        toolbox: {
          feature: {
            saveAsImage: {}
          }
        },
        xAxis: {
          type: 'category',
          boundaryGap: false,
          data: ['2020-09-01', '2020-09-02', '2020-09-03','2020-09-04', '2020-09-05', '2020-09-06','2020-09-07', '2020-09-08', '2020-09-09','2020-09-10', '2020-09-11', '2020-09-12',
            '2020-09-13', '2020-09-14', '2020-09-15', '2020-09-16','2020-09-17', '2020-09-18', '2020-09-19','2020-09-20', '2020-09-21', '2020-09-22',
            '2020-09-23', '2020-09-24', '2020-09-25', '2020-09-26','2020-09-27', '2020-09-28', '2020-09-29','2020-09-30']
        },
        yAxis: {
          type: 'value'
        },
        series: [
          {
            name: '新闻',
            type: 'line',
            stack: '总量',
            smooth:true,
            symbol:'none', //这句就是去掉点的
            data: [10, 20, 101, 134, 90, 230, 210,34,234,45,13,45,65,231,678,56,33,22,12,55,96,123,25,143,234,543,345,234,123]
          },
          {
            name: '微信',
            type: 'line',
            stack: '总量',
            smooth:true,
            symbol:'none', //这句就是去掉点的
            data: [20, 40, 191, 234, 290, 330, 310,120, 132, 101, 134, 90, 230, 210,34,234,45,13,45,65,231,453,56,33,22,220, 182, 191, 234, 290]
          },
          {
            name: '博客',
            type: 'line',
            stack: '总量',
            smooth:true,
            symbol:'none', //这句就是去掉点的
            data: [10, 50,230, 210,150, 232, 201,220, 182, 191, 234, 290, 154, 190, 34,234,45,13,45,65,231,453,56,33,22,12,55,96,123,25]
          },
          {
            name: '微博',
            type: 'line',
            stack: '总量',
            smooth:true,
            symbol:'none', //这句就是去掉点的
            data: [10,34,234,45,13,45,65,231,453,56,33,22,12,150, 232, 201,220, 182, 191, 234, 290, 154, 190, 330, 410,230,55,96,123,25]
          },
          {
            name: '论坛',
            type: 'line',
            stack: '总量',
            smooth:true,
            symbol:'none', //这句就是去掉点的
            data: [34,43,45,13,45,65,231,453,56,150, 232, 201,220, 182, 191, 234, 290, 154, 190, 330, 410,230, 210,33,22,12,55,96,123,25]
          },
          {
            name: '贴吧',
            type: 'line',
            stack: '总量',
            smooth:true,
            symbol:'none', //这句就是去掉点的
            data: [20,79,34,234,45,13,45,65,231,453,56,33,22,12,55,96,123,25,232, 201,220, 182, 191, 234, 290, 154, 190, 330, 410,230]
          },
          {
            name: 'APP',
            type: 'line',
            stack: '总量',
            smooth:true,
            symbol:'none', //这句就是去掉点的
            data: [34, 67, 201,220, 410,230, 210,34,234,45,13,45,65,231,453,56,33,22,12,55,96,123,25, 182, 191, 234, 290, 154, 190, 330]
          },
        ]
      }
    }
  },
  watch:{

  },
  mounted() {
    this.initChart()
    this.__resizeHandler = debounce(() => {
      if (this.chart) {
        this.chart.resize()
      }
    }, 100)
    window.addEventListener('resize', this.__resizeHandler)
  },
  beforeDestroy() {
    if (!this.chart) {
      return
    }
    window.removeEventListener('resize', this.__resizeHandler)
    this.chart.dispose()
    this.chart = null
  },
  methods: {
    initChart() {
      this.chart = echarts.init(this.$el, 'royal')
      this.chart.setOption(this.opinion)
    }
  }
}
</script>
